package com.gnerv.sylvanas.business.manage.logic;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.framework.core.BaseUkIdGenerate;
import com.gnerv.sylvanas.business.manage.model.bo.RouteBO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteTreeDTO;
import com.gnerv.sylvanas.business.manage.model.dto.RouteUpdateDTO;
import com.gnerv.sylvanas.business.manage.operation.RouteOperationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class RouteLogicService  {

    private final RouteOperationService routeOperationService;
    private final BaseUkIdGenerate baseUkIdGenerate;

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> create(RouteCreateDTO routeCreateDTO) {
        RouteBO routeBO = routeCreateDTO.toRouteBO();
        routeBO.setUkId(baseUkIdGenerate.generate());
        routeOperationService.create(routeBO);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> deleteByUkId(String ukId) {
        routeOperationService.deleteByUkId(ukId);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> updateByUkId(RouteUpdateDTO routeUpdateDTO) {
        RouteBO routeBO = routeUpdateDTO.toRouteBO();
        routeOperationService.updateByUkId(routeBO);
        return RestResult.ok();
    }

    
    public RestResult<RouteDTO> selectByUkId(String ukId) {
        return RestResult.ok(routeOperationService.selectByUkId(ukId));
    }

    
    public RestResult<List<RouteDTO>> selectListByName(String name) {
        return RestResult.ok(routeOperationService.selectListByName(name));
    }

    
    public RestResult<List<RouteDTO>> selectListByParentUkId(String parentUkId) {
        List<RouteDTO> routeList = routeOperationService.selectListByParentUkId(parentUkId);
        return RestResult.ok(routeList);
    }

    
    public RestResult<List<RouteTreeDTO>> selectListTreeByParentUkId(String parentUkId) {
        List<RouteTreeDTO> routeTreeDTOList = routeOperationService.selectListTreeByParentUkId(parentUkId);
        return RestResult.ok(routeTreeDTOList);
    }

}
